package com.infosys.newSimpleInvertedIndex.mapper;

import com.infosys.newSimpleInvertedIndex.entities.Employee;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 员工总表 Mapper 接口
 * </p>
 *
 * @author Tester
 * @since 2024-06-24
 */
@Mapper
public interface EmployeeMapper extends BaseMapper<Employee> {
//    @Select("SELECT employee.*, resume.resume_url, relative.name AS relative_name, relative.job_title AS relative_job_title, relative.political_title AS relative_political_title, relative.type AS relative_type FROM employee" +
//            " LEFT JOIN resume ON employee.id = resume.employee_id" +
//            " LEFT JOIN relative ON employee.id = relative.employee_id" +
//            " WHERE employee.id = #{id}")
    @Select("SELECT * FROM employee WHERE id = #{id}")
    @ResultMap("EmployeeResultMap")
    Employee getEmployeeById(@Param("id") String id);

    //LESSON: @Param is necessary when using multiple parameters, HOWEVER, this is good practice to do so with single parameters
    @Select("SELECT * FROM employee WHERE STR_TO_DATE(SUBSTR(gov_id, 7, 8), '%Y%m%d') > #{startDateStr} AND STR_TO_DATE(SUBSTR(gov_id, 7, 8), '%Y%m%d') < #{endDateStr}; ")
    List<Employee> getEmployeeByAgeRange(@Param("startDateStr") String startDateStr, @Param("endDateStr") String endDateStr);
}